home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / clipper / nfsrc21.zip / BYTENOT.PRG < prev    next >
Text File  |  1991-08-15  |  3KB  |  84 lines

  1. /*
  2.  * File......: BYTENOT.PRG
  3.  * Author....: Forest Belt, Computer Diagnostic Services, Inc.
  4.  * Date......: $Date:   15 Aug 1991 23:05:00  $
  5.  * Revision..: $Revision:   1.2  $
  6.  * Log file..: $Logfile:   E:/nanfor/src/bytenot.prv  $
  7.  * 
  8.  * This is an original work by Forest Belt and is placed in the
  9.  * public domain.
  10.  *
  11.  * Modification history:
  12.  * ---------------------
  13.  *
  14.  * $Log:   E:/nanfor/src/bytenot.prv  $
  15.  * 
  16.  *    Rev 1.2   15 Aug 1991 23:05:00   GLENN
  17.  * Forest Belt proofread/edited/cleaned up doc
  18.  * 
  19.  *    Rev 1.1   10 May 1991 23:54:40   GLENN
  20.  * Documentation correction.  The "oneliner" said two characters were NOTted,
  21.  * but this function just takes one byte.
  22.  * 
  23.  *    Rev 1.0   01 Apr 1991 01:00:54   GLENN
  24.  * Nanforum Toolkit
  25.  *
  26.  */
  27.  
  28.  
  29.  
  30. /*  $DOC$
  31.  *  $FUNCNAME$
  32.  *     FT_BYTENOT()
  33.  *  $CATEGORY$
  34.  *     String
  35.  *  $ONELINER$
  36.  *     Perform bit-wise NOT on an ASCII character (byte)
  37.  *  $SYNTAX$
  38.  *     FT_BYTENOT( <cByte> ) -> cNewByte
  39.  *  $ARGUMENTS$
  40.  *     <cByte> is a character from CHR(0) to CHR(255).
  41.  *     May be passed in CHR() form, as character literal, or
  42.  *     as expression evaluating to CHR() value.
  43.  *  $RETURNS$
  44.  *     Returns resulting byte, in CHR() form.  If parameters are faulty,
  45.  *     returns NIL.
  46.  *  $DESCRIPTION$
  47.  *     Can be used for bitwise byte manipulation.  In effect, this is a
  48.  *     bit-by-bit NOT (one's complement) operation.  Equivalent to the
  49.  *     NOT assembler instruction.
  50.  *
  51.  *     This function is presented to illustrate that bit-wise operations
  52.  *     are possible with Clipper code.  For greater speed, write .C or
  53.  *     .ASM versions and use the Clipper Extend system.
  54.  *  $EXAMPLES$
  55.  *     This code performs a bitwise NOT on byte represented by CHR(32):
  56.  *
  57.  *          cNewByte := FT_BYTENOT( CHR(32) )
  58.  *          ? ASC( cNewByte )     // result: 223
  59.  *
  60.  *     For a demonstration of Clipper bit manipulations, compile and
  61.  *     link the program BITTEST.PRG in the Nanforum Toolkit source code.
  62.  *  $SEEALSO$
  63.  *     FT_BYTEOR() FT_BYTEXOR() FT_BYTENEG() FT_BYTEAND()
  64.  *  $END$
  65.  */
  66.  
  67. FUNCTION FT_BYTENOT(cByte)
  68.  
  69.   LOCAL nCounter, cNewByte
  70.  
  71.   IF valtype(cByte) != "C"
  72.      cNewByte := NIL
  73.   ELSE
  74.      cNewByte := chr(0)
  75.      FOR nCounter := 0 to 7           // test each bit position
  76.         IF .not. FT_ISBIT(cByte, nCounter)
  77.            cNewByte := FT_BITSET(cNewByte, nCounter)
  78.         ENDIF
  79.      NEXT
  80.   ENDIF
  81.  
  82. RETURN cNewByte
  83.  
  84.